package com.YHVision.qiuzhike.model.vo;

import cn.hutool.json.JSONUtil;
import com.YHVision.qiuzhike.model.entity.Company;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 企业视图
 *
 * @author <a href="">YHVision-小y</a>
 * @from <a href="todo">爱编程学习圈</a>
 */
@Data
public class CompanyVO implements Serializable {

    /**
     * id
     */
    private Long id;

    /**
     * 企业名称
     */
    private String companyName;

    /**
     * 企业简介
     */
    private String companyProfile;

    /**
     * 企业认证状态：0未认证，1已认证
     */
    private Integer isVerified;

    /**
     * 行业列表
     */
    private List<String> industryList;

    /**
     * 创建用户 id
     */
    private Long userId;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * 创建用户信息
     */
    private UserVO user;

    /**
     * 浏览量
     */
    private Integer viewNum;

    /**
     * 是否已点赞
     */
    private Boolean hasThumb;

    /**
     * 是否已收藏
     */
    private Boolean hasFavour;

    /**
     * 封装类转对象
     *
     * @param companyVO
     * @return
     */
    public static Company voToObj(CompanyVO companyVO) {
        if (companyVO == null) {
            return null;
        }
        Company company = new Company();
        BeanUtils.copyProperties(companyVO, company);
        List<String> industryList = companyVO.getIndustryList();
        company.setIndustry(JSONUtil.toJsonStr(industryList));
        return company;
    }

    /**
     * 对象转封装类
     *
     * @param company
     * @return
     */
    public static CompanyVO objToVo(Company company) {
        if (company == null) {
            return null;
        }
        CompanyVO companyVO = new CompanyVO();
        BeanUtils.copyProperties(company, companyVO);
        companyVO.setIndustryList(JSONUtil.toList(JSONUtil.parseArray(company.getIndustry()), String.class));
        return companyVO;
    }
}
